﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.data {
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.vo.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;

    public class StoreShopDataCommand extends Command {

        private const ELEMENT:int = 0;
        private const DESTINATION:int = 1;
        private const CATEGORY:int = 2;
        private const LINE:int = 3;
        private const POSITION:int = 4;
        private const UNIQUE:int = 5;
        private const BACKGROUND:int = 6;
        private const GIFTABLE:int = 7;
        private const COINS:int = 8;
        private const CASH:int = 9;
        private const SELL_FOR:int = 10;
        private const CHARMING_POINTS:int = 11;
        private const XP:int = 12;
        private const MIN_FRIENDS:int = 13;
        private const MIN_LEVEL:int = 14;
        private const NEW_UNTIL:int = 15;
        private const AVAILABLE_FROM:int = 16;
        private const AVAILABLE_UNTIL:int = 17;

		[Inject]
        public var event:InfoEvent;
		[Inject]
        public var shopModel:ShopModel;
		[Inject]
        public var sessionModel:SessionModel;
		[Inject]
        public var environmentModel:EnvironmentModel;
		[Inject]
        public var fileInfoModel:FileInfoModel;

        override public function execute():void{
            var _local2:ShopItemVO;
            var _local3:Array;
            var _local1:Array = (this.event.info as Array);
            for each (_local3 in _local1) {
                _local2 = new ShopItemVO();
                _local2.type = _local3[this.ELEMENT];
                _local2.destination = _local3[this.DESTINATION];
                _local2.category = _local3[this.CATEGORY];
                _local2.row = _local3[this.LINE];
                _local2.position = _local3[this.POSITION];
                _local2.unique = _local3[this.UNIQUE];
                _local2.background = _local3[this.BACKGROUND];
                _local2.giftable = _local3[this.GIFTABLE];
                _local2.coins = _local3[this.COINS];
                _local2.cash = _local3[this.CASH];
                _local2.sellFor = _local3[this.SELL_FOR];
                _local2.charmingPoints = _local3[this.CHARMING_POINTS];
                _local2.xp = _local3[this.XP];
                _local2.minFriends = _local3[this.MIN_FRIENDS];
                _local2.minLevel = _local3[this.MIN_LEVEL];
                _local2.newUntil = _local3[this.NEW_UNTIL];
                _local2.availableFrom = _local3[this.AVAILABLE_FROM];
                _local2.availableUntil = _local3[this.AVAILABLE_UNTIL];
                _local2.location = this.shopModel.getLocationByDestination(_local2.destination);
                _local2.isOneShotItem = this.isOneShotItem(_local2);
                _local2.assetURL = this.getURL(_local2.type);
                if (this.belongsItemToShop(_local2)){
                    this.shopModel.addShopItem(_local2);
                };
            };
        }
        private function isOneShotItem(_arg1:ShopItemVO):Boolean{
            var _local2:String = _arg1.type;
            return ((((((_local2 == GameConstants.TYPE_KIOSK)) || ((_local2 == GameConstants.TYPE_KINDERGARTEN)))) || ((_local2 == GameConstants.TYPE_FOUNTAIN))));
        }
        private function belongsItemToShop(_arg1:ShopItemVO):Boolean{
            var _local2:String;
            if (_arg1.isRoom()){
                _local2 = _arg1.type;
                if ((((((((_local2 == GameConstants.TYPE_BATTERY_ROOM)) || ((_local2 == GameConstants.TYPE_ENTRANCE_AREA)))) || ((_local2 == GameConstants.TYPE_RECEPTION)))) || ((_local2 == GameConstants.TYPE_WAITING_ROOM)))){
                    return (false);
                };
            };
            return (true);
        }
        private function getURL(_arg1:String):String{
            var _local2 = (("assets/shop/" + _arg1) + ".swf");
            _local2 = _local2.toLowerCase();
            if (!this.environmentModel.localVersion){
                _local2 = this.fileInfoModel.getCdnUrl(_local2);
            };
            return (_local2);
        }

    }
}//package net.wooga.pets.controllers.data 
